package com.bluesky.plum.richdomain;

import java.lang.reflect.Method;
import java.util.Map;

import com.bluesky.plum.richdomain.annotation.OUMMethod;
import com.bluesky.plum.util.FieldUtil;

public class RichDomainMethod implements Comparable<RichDomainMethod> {

	public Object object;

	public Method method;

	public Map<String,Class> genericTypeMap;
	
	public String caption;

	public String desc;

	public int position;

	public boolean enabled;

	public Class formBuilder;

	public RichDomainMethod(Object object, Method m, Map<String,Class> genericTypeMap) {
		if (m.isAnnotationPresent(OUMMethod.class)) {
			OUMMethod om = m.getAnnotation(OUMMethod.class);

			this.formBuilder = om.formBuilder();
			this.object = object;
			this.method = m;
			this.genericTypeMap=genericTypeMap;
			this.caption = om.caption();
			this.desc = om.desc();
			this.enabled = om.enabled();
			this.position = om.position();
		}
	}

	@Override
	public String toString() {
		 return String.format("%s", method);
	}

	@Override
	public int compareTo(RichDomainMethod o) {
		int v = position - o.position;
		if (v != 0)
			return v;

		return method.getName().compareTo(o.method.getName());
	}
}
